package com.lujianfei.mqtt.login

import android.view.View
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
import com.blankj.utilcode.util.ToastUtils
import com.lujianfei.mqtt.BaseViewModel
import com.lujianfei.mqtt.login.mvvm.ILoginRepository
import com.lujianfei.mqtt.login.mvvm.LoginReq
import com.lujianfei.mqtt.login.mvvm.UserInfo
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2024/4/15 15:59
 * @Description: 登陆的 ViewModel
 */
@HiltViewModel
class LoginViewModel @Inject constructor(private val repository: ILoginRepository): BaseViewModel()  {

  val obMobile = ObservableField("张三")// 账号
  val obPassword = ObservableField("123")// 密码

  /**
   * 检测账号是否注册过
   */
 private fun checkRegister() {}

  val userInfo = repository.loginRsp

  /**
   * 登录请求
   */
  fun requestLogin() {
    val account = obMobile.get() ?: return
    val password = obPassword.get() ?: return
    apiLaunch {
      repository.requestLogin(LoginReq(account, password))
    }
  }

  fun forget(v: View) = ToastUtils.showShort("静态点击方式 ${v.context.packageName}")
}